package com.extra_archive.project.iisu.view.detail.presentation 
{

	import com.extra_archive.framework.media.video.FLVPlayer;

	import org.papervision3d.materials.MovieAssetMaterial;
	import org.papervision3d.objects.DisplayObject3D;
	import org.papervision3d.objects.primitives.Plane;

	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.utils.getDefinitionByName;

	/**
	 * @ Class Name : ContentPlane.as
	 * @ Author : seenix
	 * @ Up Date : 2010. 5. 8.
	 */
	public class ContentPlane extends DisplayObject3D 
	{
		private var _id : uint;
		private var _flvPlayer : FLVPlayer;
		private var _videoUrls : Array = ["", "../flv/universalFrame.flv", "../flv/universalFacade.flv", "../flv/hyperFacade.flv", "../flv/hyperStage.flv" ];
		private var _clip : Plane;

		public function ContentPlane(id : uint)
		{
			_id = id;
			
			initialize();
		}
		
		public function get clip() : Plane
		{
			return _clip;
		}
		
		//--------------------------------------------------------------------------
		//
		//    Public Methods
		//
		//--------------------------------------------------------------------------
			
		public function initialize() : void 
		{
			if (_id == 0) createImgClip();
			else createVideoClip();
			
			//initModifier();
		}
		
		public function live() : void
		{
			if (_flvPlayer) _flvPlayer.play(_videoUrls[_id]);
			
			//TODO : 등장효과
		}

		public function kill() : void
		{
			if (_flvPlayer) _flvPlayer.stop();
		}
		
		//--------------------------------------------------------------------------
		//
		//    Event Listeners
		//
		//--------------------------------------------------------------------------

		private function createImgClip() : void 
		{
			var mat : MovieAssetMaterial = new MovieAssetMaterial("imgClip", true);
			mat.smooth = true;
			_clip = new Plane(mat, mat.bitmap.width, mat.bitmap.height, 3, 3);
			_clip.x = -10;
			_clip.y = 10;
			_clip.z = -1;
			addChild(_clip);
		}
		
		private function createVideoClip() : void 
		{
			var mat : MovieAssetMaterial = new MovieAssetMaterial("videoClip" + _id, true, true);
			mat.smooth = true;
			_clip = new Plane(mat, MovieAssetMaterial(mat).movie.width, MovieAssetMaterial(mat).movie.height, 3, 3);
			_clip.x = -20;
			_clip.y = 14; 
			addChild(_clip);
			
			_flvPlayer = new FLVPlayer(245, 151);
			_flvPlayer.x = 23;
			_flvPlayer.y = 104;
			_flvPlayer.play(_videoUrls[_id]);
			_flvPlayer.stop();
			MovieClip(mat.movie).addChild(_flvPlayer);
		}

		private function getLibraryAsset(name : String) : DisplayObject
		{
			var cls : Class = getDefinitionByName(name) as Class;
			return new cls();		
		}
	}
}
